package com.dreem.principle.ocp.improve;

/**
 * @program: DesignParrtern
 * @description: 运用开闭原则
 * @author: Peng
 * @create: 2021-01-16  23:00
 **/
public class OcpUP {
    public static void main(String[] args){
        Graphic graphic = new Graphic();
        graphic.draw(new RectangleUp());
        graphic.draw(new Triangle());
        graphic.draw(new CircleUp());
    }
}

// 一个用于绘图的类[使用方]
class Graphic{
    // 接收Shape对象，调用draw方法
    public void draw(ShapeUp shapeUp){
        shapeUp.draw();
    }
}

// Shape类，基类
abstract class ShapeUp{
    int m_type;
    public abstract void draw();// 抽象方法
}

class RectangleUp extends ShapeUp {

    RectangleUp(){
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println(" 绘制矩形 ");
    }
}

class Triangle extends ShapeUp {

    Triangle(){
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println(" 绘制三角形 ");
    }
}

class CircleUp extends ShapeUp {

    CircleUp(){
        super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println(" 绘制圆形 ");
    }
}